<?php
$database_local = 'test_arcade_live';
#$database_local = 'con_arcades';
#$database_remote = 'test_arcade_live';
$database_remote = 'test_arcade_staging';

/**
* How to find out the list of table names to check matching status?
* @param String "config": Fetches table names from a configuration file: mismatched.ini
* @param String "query": Makes a live query on the database on both sides (local/remote) to build a list of tables
*/
#$table_names_collection_method='config'; # config | query
$table_names_collection_method='query'; # config | query

/**
* Matches two table structures and lists out the mismatched ones.
* Each of the databases should be accessible with single user account.
* @todo implement it inside the framework.
*/
# Where is your Sanjaal Framework located at?
require_once('../../smarty-framework/public_html/library/inc/inc.config.php');
#print_r(get_defined_constants(true)['user']);
chdir(dirname(__FILE__));

$db_local  = new mysql();
$db_remote = new mysql();

/**
* Better alternative to mysql_list_tables (depricated)
*/
function mysql_tables($database='')
{
	$tables = array();
	$list_tables_sql = "SHOW TABLES FROM {$database};";
	$result = mysql_query($list_tables_sql);
	if($result)
	while($table = mysql_fetch_row($result))
	{
		$tables[] = $table[0];
	}
	return $tables;
}

$tables=array();
if($table_names_collection_method=='query')
{
	/**
	* Let us directly scan the table names in each databases and build a unique list
	*/
	$tables = array_merge(
		mysql_tables($database_local),
		mysql_tables($database_remote)
	);
}
else
{
	/**
	* Alternative way of collecting list of table names from a configration filename
	* The ini file is a list of tables to compare
	*/
	$tables_list = 'mismatched.ini';
	
	if(is_file($tables_list))
	{
		$tables = preg_split('/[\r|\n]+/is', file_get_contents($tables_list));
	}
	else
	{
		die("Cannot read the config file <strong>{$tables_list}</strong> to list the table names.");
	}
}

# Remove any duplicate names
$tables = array_unique($tables);
sort($tables, SORT_STRING);
?>